﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.Security;
public partial class LogIn : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["PAS_DB"].ConnectionString;
        String query = "select username, password from homelogin";
        SqlCommand cmd = new SqlCommand(query, con);
        con.Open();
        SqlDataReader rd = cmd.ExecuteReader();
        bool userFound = false;
        while (rd.Read())
        {
            if (rd[0].ToString() == Login1.UserName && rd[1].ToString() == Login1.Password)
            {
                userFound = true;
                break;
            }
        }
        rd.Close();
        con.Close();

        if (userFound)
        {
            FormsAuthentication.Authenticate(Login1.UserName, Login1.Password);
            FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet);
            String name = Login1.UserName;
            Response.Redirect("Welcome.aspx?username=" + name);
           
        }
    }
}